Skip to content

Conversation

carlosascari
Copy link

When using the conditionalHandler plugin, if a single version route has a contentType, but the other routes do not, it will crash as it tries to call .join on a undefined contentType field.

See for yourself:

const restify = require('restify');

const server = restify.createServer();

server.get('/', restify.plugins.conditionalHandler([
  {
    contentType: ['application/json'],
    version: '1.5.0', 
    handler: (req, res, next) => {
      res.json({
        version: 0
      })
    }
  },
  {
    // contentType is missing here
    version: '1.1.0', 
    handler: (req, res, next) => {
      res.json({
        version: 1
      })
    }
  }
]));

Pre-Submission Checklist

  • Opened an issue discussing these changes before opening the PR
  • Ran the linter and tests via make prepush
  • Included comprehensive and convincing tests for changes

Issues

Closes:

  • Issue #
  • Issue #
  • Issue #

Summarize the issues that discussed these changes

Changes

What does this PR do?

When using the **conditionalHandler** plugin, if a single version route has a `contentType`, but the other routes do not, it will crash as it tries to call `.join` on a undefined `contentType` field.

See for yourself:

``` bug.js
const restify = require('restify');

const server = restify.createServer();

server.get('/', restify.plugins.conditionalHandler([
  {
    contentType: ['application/json'],
    version: '1.5.0', 
    handler: (req, res, next) => {
      res.json({
        version: 0
      })
    }
  },
  {
    // contentType is missing here
    version: '1.1.0', 
    handler: (req, res, next) => {
      res.json({
        version: 1
      })
    }
  }
]));
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant